<script>
	
	var client
	export default {
		data() {
			return {
				topic: '' //要订阅的主题
			}
		},
		onLaunch: function() {
			console.log('App Launch')
			//this.connect() //连接
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hidess')
		},
		methods: {
			gotoHome() {
				// 关闭所有页面，打开到应用内的某个页面。
				console.log("gotoHome");
				uni.reLaunch({
					url: '/pages/home/home',
					animationType: 'pop-in',
					animationDuration: 300
				})
			},
			connect() {
				MQTT_OPTIONS.clientId = v4()
				var that = this
				// #ifdef H5
				client = mqtt.connect('ws://' + MQTT_IP, MQTT_OPTIONS)
				// #endif
				// #ifdef MP-WEIXIN||APP-PLUS
				client = mqtt.connect('wx://' + MQTT_IP, MQTT_OPTIONS)
				// #endif
				client.on('connect', function() {
					console.log('连接成功')
					client.subscribe(that.topic, function(err) {
						if (!err) {
							console.log('订阅成功')
						}
					})
				}).on('reconnect', function(error) {
					console.log('正在重连...', that.topic)
				}).on('error', function(error) {
					console.log('连接失败...', error)
				}).on('end', function() {
					console.log('连接断开')
				}).on('message', function(topic, message) {
					console.log('接收推送信息：', message.toString())
				})
			}
		}
	}
</script>

<style>

	/* 字节（头条）小程序组件内不能引入字体，需要在页面中条件编译引入 */
	/* #ifdef MP-TOUTIAO */
	@font-face {
		font-family: 'fuiFont';
		src: url("~@/components/firstui/fui-icon/fui-icon.ttf") format("truetype");
	}

	/* #endif */

	/*每个页面公共css */
	.uni-tabbar-bottom {
		display: none;
	}

	uni-page-wrapper {
		height: 100% !important;
	}

	.uni-app--showtabbar uni-page-wrapper::after {
		display: none !important;
	}

	uni-page-body {
		height: 100%;
	}

	uni-page-head {
		display: none;
	}

	page {
		font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
		height: 100%;
	}

	.space {
		flex: 1;
	}


	.container {
		
	}

	.myPage {
		display: flex;
		flex-direction: column;
		height: 100%;
		position: relative;
		background: #f9f9f9;
	}


	.custom-navbar {
		--td-navbar-bg-color: none;
	}

	.shadowback {
		box-shadow: 0 0 20px rgb(89 102 122 / 10%) !important;
	}

	.shadowback2 {
		box-shadow: 0 2px 12px rgba(50, 50, 51, .12);
	}

	/*中间的过度的横线*/
	.link-top {
		width: 50%;
		height: 1px;
		border-top: solid #ACC0D8 1px;
	}

	/*画一条再右边的竖线*/
	.link-column {
		margin: 8rpx;
		border-right: solid #ACC0D8 1px;
	}
</style>